<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 租户机器人授权管理接口控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\TenantRobotUserCertificateService;
use think\Request;

class TenantRobotUserCertificateController extends VerifyController
{

    /**
     * @var TenantRobotUserCertificateService
     */
    private TenantRobotUserCertificateService $tenantRobotUserCertificateService;

    public function __construct()
    {
        parent::__construct();
        $this->tenantRobotUserCertificateService = new TenantRobotUserCertificateService();
    }

    /**
     * 创建机器人秘钥证书
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function create(Request $request)
    {
        try {
            $res = $this->tenantRobotUserCertificateService->create($request->param()['data']);
            return json(success_response("OK", $res));

        } catch (\Throwable $e) {
            trace(format_exception_info($e), "ERR");
            throw  $e;
        }
    }

    /**
     * 查询机器人信息
     * @param Request $request
     * @return \think\Response
     */
    public function findByCode(Request $request)
    {
        $res = $this->tenantRobotUserCertificateService->findByCode($request->param()['param']['code'], $request->getTenantId());
        return json(success_response("OK", $res));
    }
}